Catch test case order [on hold]

Posted by DeadMG on Stack Overflow See other posts from Stack Overflow or by DeadMG
Published on 2013-10-30T21:45:48Z Indexed on 2013/10/31 21:55 UTC
Read the original article Hit count: 91

Filed under:
|

Can I guarantee the order of execution with multiple TEST_CASEs with Catch? I am testing some code using LLVM, and they have some despicable global state that I need to explicitly initialize.

Right now I have one test case that's like this:

TEST_CASE("", "") {
    // Initialize really shitty LLVM global variables.
    llvm::InitializeAllTargets();
    llvm::InitializeAllTargetMCs();
    llvm::InitializeAllAsmPrinters();
    llvm::InitializeNativeTarget();
    llvm::InitializeAllAsmParsers();
    // Some per-test setup I can make into its own function
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile(...));
    CHECK_NOTHROW(Compile...));
    CHECK_NOTHROW(Interpret(...));
    CHECK_THROWS(Compile(...));
    CHECK_THROWS(Compile(...));
}

What I want is to refactor it into three TEST_CASE,

  • one for tests that should pass compilation,
  • one for tests that should fail, and -one for tests that should pass interpretation (and in the future, further such divisions, perhaps).

But I can't simply move the test contents into another TEST_CASE because if that TEST_CASE is called before the one that sets up the inconvenient globals, then they won't be initialized and the testing will spuriously fail.

© Stack Overflow or respective owner

Related posts about c++

Related posts about catch-unit-test